package com.zlzxm.shoesmarket.viewmodel;

import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.ViewModel;

import com.zlzxm.shoesmarket.TestConstant;
import com.zlzxm.shoesmarket.util.RxAndroidHelp;
import com.zlzxm.shoesmarket.view.adapter.entity.EntityBuySaleAllInfo;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;

import io.reactivex.rxjava3.annotations.NonNull;
import io.reactivex.rxjava3.core.Observable;
import io.reactivex.rxjava3.core.Observer;
import io.reactivex.rxjava3.disposables.Disposable;

/**
 * CREATE BY zlzxm ON 4/14/21
 */
public class VMBuySaleAll extends ViewModel {

    private MutableLiveData<List<EntityBuySaleAllInfo>> liveGoodsInfo = new MutableLiveData<>();

    public MutableLiveData<List<EntityBuySaleAllInfo>> getLiveGoodsInfo() {
        return liveGoodsInfo;
    }

    public void requestGoodsInfo(){


        Observable.timer(3, TimeUnit.SECONDS)
                .compose(RxAndroidHelp.turn())
                .subscribe(new Observer<Long>() {
                    @Override
                    public void onSubscribe(@NonNull Disposable d) {

                    }

                    @Override
                    public void onNext(@NonNull Long aLong) {

                    }

                    @Override
                    public void onError(@NonNull Throwable e) {

                    }

                    @Override
                    public void onComplete() {

                        liveGoodsInfo.setValue(createTestData());
                    }
                });



    }


    //<editor-fold defaultState="collapsed" desc="测试">


    private List<EntityBuySaleAllInfo>  createTestData(){

        List<EntityBuySaleAllInfo> list = new ArrayList<>();

        for (int i = 0; i < 10; i++) {

            EntityBuySaleAllInfo entity =    new EntityBuySaleAllInfo();
            entity.setTitle("123312");
            entity.setDesc("货号：xxxxxxxx  品牌：xxxxx");
            entity.setUrl(TestConstant.PIC_FIVE);
            entity.setIn("1231");
            entity.setSaleMoney("1231");
            entity.setOut("1231");
            entity.setProfit("1231");
            entity.setSave("1231");
            entity.setProfitRate("1231");
            entity.setCost("1231");
            entity.setDays("1231");


            list.add(entity);
        }

        return list;
    }


    // </editor-fold>
}
